﻿namespace AuthServer
{
    public static class CrosServiceExtension
    {
        /// <summary>
        /// 配置跨域的
        /// </summary>
        /// <param name="builder"></param>
        public static void AddDomainsPolicy(this WebApplicationBuilder builder)
        {
            builder.Services.AddCors(option =>
            {
                option.AddPolicy("AllCrosDomainsPolicy", builder => 
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
        }


        /// <summary>
        /// 中间件中配置支持跨域
        /// </summary>
        /// <param name="app"></param>
        public static void UseDomainsPolicy(this WebApplication app)
        {
            app.UseCors("AllCrosDomainsPolicy");
        }
    }
}
